import os
import re

def rename_files_in_place(input_dir):
    # 获取输入目录中的所有.npy文件
    files = [f for f in os.listdir(input_dir) if f.endswith('.npy')]

    for file in files:
        match = re.search(r'tr(\d+)-tc(\d+)', file)
        if match:
            tr = int(match.group(1))
            tc = int(match.group(2))
            new_name = f"tile_({tr-1}_{tc-1},{tr}_{tc}).npy"
            old_path = os.path.join(input_dir, file)
            new_path = os.path.join(input_dir, new_name)
            os.rename(old_path, new_path)
            print(f"Renamed {file} to {new_name}")

    print("All files have been renamed in the input directory.")

# 示例用法
input_dir = r'E:\wafer52\11867_32nm_fine_align_512_dvf(1)'  # 替换为实际输入文件夹路径

rename_files_in_place(input_dir)
